package cn.wit.summit.chwan.widgets;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.utils.StringUtils;

/**
 * Created by tangbl on 2018/4/20.
 */

public class CurrencyPromptDialog extends AlertDialog {

    private TextView currencyPromptTitleTx;
    private TextView currencyPromptMsgTx;
    private Button currencyPromptBt;
    private Button currencyPromptCancelBt;
    private Button currencyBt;
    private ImageView cancelIv;
    public CurrencyPromptDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setCancelable(false);  //是否获取界外焦点
        Window dialogWindow = getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.CENTER);
        setContentView(R.layout.dialog_currency_prompt_view);
        currencyPromptTitleTx = findViewById(R.id.currencyPromptTitleTx);
        currencyPromptMsgTx = findViewById(R.id.currencyPromptMsgTx);
        currencyPromptBt = findViewById(R.id.currencyPromptBt);
        currencyPromptCancelBt = findViewById(R.id.currencyPromptCancelBt);
        cancelIv = findViewById(R.id.cancelIv);
        currencyBt = findViewById(R.id.currencyBt);

        cancelIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    public void setCancelIvGone() {
        this.cancelIv.setVisibility(View.INVISIBLE);
    }

    public void setOkBtn(String txt, View.OnClickListener clickListener) {
        currencyPromptBt.setVisibility(View.VISIBLE);
        currencyPromptBt.setOnClickListener(clickListener);
        currencyPromptBt.setText(txt);
    }

    public void setBtn(View.OnClickListener clickListener) {
        setBtn("", clickListener);
    }
    public void setBtn(String txt, View.OnClickListener clickListener) {
        if (StringUtils.isEmpty(txt)) {
            txt = getContext().getResources().getString(R.string.updata_dialog_cancle_str);
        }
        currencyBt.setVisibility(View.VISIBLE);
        currencyBt.setOnClickListener(clickListener);
        currencyBt.setText(txt);
    }

    public void setCancleBtn(String txt, View.OnClickListener clickListener) {
        currencyPromptCancelBt.setOnClickListener(clickListener);
        currencyPromptCancelBt.setText(txt);
    }

    public void setMsg(String txt) {
        currencyPromptMsgTx.setText(txt);
    }

    public void setTitle(String txt) {
        currencyPromptTitleTx.setText(txt);
    }

}
